package cmdb

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"minefieldplatform-go/app/service/cmdb"
	"strings"
)

// Hello is a demonstration route handler for output "Hello World!".
func GpuList(r *ghttp.Request) {
	gpuList, count := cmdb.GetGpuList()

	r.Response.WriteJson(g.Map{
		"code":  0,
		"msg":   "",
		"count": count,
		"data":  gpuList,
	})
}

func GpuAdd(r *ghttp.Request) {
	var data = g.Map{
		"ip":           r.Get("ip"),
		"cpu_cores":    r.Get("cpu"),
		"total_memory": r.Get("memory"),
		"gpu_numbers":  r.Get("gpu"),
		"area":         r.Get("area"),
		"node_status":  r.Get("node_status"),
	}
	cmdb.GpuAddData(data)
}

func GpuDel(r *ghttp.Request) {
	id := r.Get("id")
	cmdb.GpuDelData(id)
}

func GpuUpdate(r *ghttp.Request) {
	var data = g.Map{
		"id":           r.Get("id"),
		"ip":           r.Get("ip"),
		"cpu_cores":    r.Get("cpu"),
		"total_memory": r.Get("memory"),
		"gpu_numbers":  r.Get("gpu"),
		"area":         r.Get("area"),
		"node_status":  r.Get("node_status"),
	}
	cmdb.GpuUpdateData(data, data["id"])
}

func GpuDelAll(r *ghttp.Request) {
	ids := r.GetFormArray("ids")
	a := strings.Split(ids[0], ",")
	v := g.Slice{}
	for _, i := range a {
		v = append(v, i)
	}

	cmdb.GpuDelAll(v)
}
